// 这个模块主要提供 一些方法和类型

// 管理员默认路由
let adminRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'classJur',     // 对老师，学生的权限设置
                name: 'classJur',
                meta: {
                    id: 41,
                    icon: "el-icon-position",
                    title: "分类权限管理",
                    roles: ["admin"]
                },

            },
            {
                path: 'userJur',     // 对单独地用户的权限设置
                name: 'userJur',
                meta: {
                    id: 42,
                    icon: "el-icon-thumb",
                    title: "用户权限管理",
                    roles: ["admin"]
                },

            },
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'authentication',  // 老师资格认证模块
                name: 'authentication',
                meta: {
                    id: 53,
                    icon: "el-icon-menu",
                    title: "教师资格认证",
                    roles: ["admin"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'college',  // 毕业生学院详情
                name: 'college', 
                meta: {
                    id:25,
                  title: "学院详情",
                  icon: "el-icon-s-data",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/echarts/college')
              },
              {
                path: 'major',  // 毕业生专业详情  
                name: 'major',
                meta: {
                    id:26,
                  title: "专业详情",
                  icon: "el-icon-s-marketing",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/echarts/major')
              },

        ]
    },
]

// 老师默认路由 最大的权限
let teacherRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'college',  // 毕业生学院详情
                name: 'college', 
                meta: {
                  title: "学院详情",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/college')
              },
              {
                path: 'major',  // 毕业生专业详情
                name: 'major',
                meta: {
                  title: "专业详情",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/major')
              },


        ]
    },
]

// 学生默认路由  最大的权限
let studentRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'college',  // 毕业生学院详情
                name: 'college', 
                meta: {
                  title: "学院详情",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/college')
              },
              {
                path: 'major',  // 毕业生专业详情
                name: 'major',
                meta: {
                  title: "专业详情",
                  roles: ["admin", "teacher", "student"]
                },
                component: () => import(/* webpackChunkName: "echarts" */ '../views/home/major')
              },

        ]
    },

]

// 导出一个专门处理 权限id数组和这儿的路由表的对应关系的函数
function handleJur(arr) {
    let newadminRouter = [{
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: []
    }]

    for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < studentRouter[0].children.length; j++) {
            if (studentRouter[0].children[j].meta.id == arr[i]) {
                newadminRouter[0].children.push(studentRouter[0].children[j])
            }
        }
    }

    // console.log(newadminRouter)

    return newadminRouter
}

// 定义院校结构
let colleges=[
    {
        value: "信息工程学院",
        label: "信息工程学院",
        id:0,
        children: [
            {
                id:1,
                value: "自动化",
                label: "自动化",
            },
            {
                id:2,
                value: "电子信息",
                label: "电子信息",
            },
            {
                id:3,
                value: "计算机科学与技术",
                label: "计算机科学与技术",
            },
            {
                id:4,
                value: "信息管理",
                label: "信息管理",
            },
        ],
    },
    {
        id:10,
        value: "文学院",
        label: "文学院",
        children: [
            {
                id:11,
                value: "汉语言文学",
                label: "汉语言文学",
            },
            {
                id:12,
                value: "汉语国际教育",
                label: "汉语国际教育",
            },
        ],
    },
    {
        id:20,
        value: "外国语学院",
        label: "外国语学院",
        children: [

            {
                id:21,
                value: "英语(师范)",
                label: "英语(师范)",
            },
            {
                id:22,
                value: "翻译",
                label: "翻译",
            },
            {
                id:23,
                value: "商务英语",
                label: "商务英语",
            },
            {
                id:24,
                value: "日语",
                label: "日语",
            },
        ],
    },
    {
        id:30,
        value: "数学科学学院",
        label: "数学科学学院",
        children: [
            {
                id:31,
                value: "数学与应用数学",
                label: "数学与应用数学",
            },
            {
                id:32,
                value: "信息与计算科学",
                label: "信息与计算科学",
            },
            {
                id:33,
                value: "统计学",
                label: "统计学",
            },
        ],
    },
    {
        id:40,
        value: "物理科学与技术学院",
        label: "物理科学与技术学院",
        children: [
            {
                id:41,
                value: "物理学",
                label: "物理学",
            },
            {
                id:42,
                value: "电子信息科学与技术",
                label: "电子信息科学与技术",
            },
            {
                id:43,
                value: "微电子科学与工程",
                label: "微电子科学与工程",
            },
            {
                id:44,
                value: "光电信息科学与技术",
                label: "光电信息科学与技术",
            },
        ],
    },
    {
        value: "化学化工学院",
        label: "化学化工学院",
        children: [
            {
                id:50,
                value: "化学",
                label: "化学",
            },
            {
                id:51,
                value: "应用化学",
                label: "应用化学",
            }, 
            {
                id:52,
                value: "高分子材料与工程",
                label: "高分子材料与工程",
            },
            {
                id:53,
                value: "化学工程与工艺",
                label: "化学工程与工艺",
            },
            {
                id:54,
                value: "制药工程",
                label: "制药工程",
            },
        ],
    }
]

// 二分法查找数据
	
function getIndex(searchElement, fromIndex) {

    var len = this.length;

    // 首先判断 fromIndex 是否合法
    if (fromIndex == null) {
        fromIndex = 0;
    }
    if (fromIndex < 0) {
        fromIndex = len - 1;
    }

    // 循环判断 searchElement 是否与数组内元素相等
    for (var i = fromIndex; i < len; i++) {
        // 如果相等则返回当前索引值
        if (searchElement === this[i]) {
            return i;
        }
    }

    return -1
}


// function getIndex(arr,key){
    
//             let low = 0;
//             let high = arr.length-1;
//             while(low<=high){
//                 // console.log("卡住了")
//                 let mid = Math.floor((low+high)/2);
//                 if(key===arr[mid]){
//                     return mid;
//                 }else if(key>arr[mid]){
//                     low = mid+1;
//                 }else{
//                     height = mid-1;
//                 }
//             }
//             return -1;
// }


module.exports = {
    getIndex,
    handleJur,
    adminRouter,
    teacherRouter,
    studentRouter,
    colleges
}